package com.shuwang.util;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;


/***
 * 手机端接收excel表
 * */
public class ExcelTest1 {
	public static void getImage(String path) throws Exception {
		URL url = new URL(
				"http://192.168.0.241:8080/zzwy/web/app.do?xlsx");
		HttpURLConnection conn = (HttpURLConnection) url.openConnection();// 基于HTTP协议的连接对象
		conn.setConnectTimeout(5000);// 请求超时时间 5s
		conn.setRequestMethod("GET");// 请求方式

		if (conn.getResponseCode() == 200) {// 响应码==200 请求成功
			InputStream inputStream = conn.getInputStream();// 得到输入流
			ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();
			byte[] buffer = new byte[1024];
			int len = 0;

			while ((len = inputStream.read(buffer)) != -1) {
				arrayOutputStream.write(buffer, 0, len);
			}
			
			FileOutputStream fos = null;
			try {
				fos = new FileOutputStream(new File("E://output.xls"));
//				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				// Put data in your baos

				arrayOutputStream.writeTo(fos);
			} catch (IOException ioe) {
				ioe.printStackTrace();
			} finally {

			}
			
			inputStream.close();
			arrayOutputStream.close();
		}
		 
//		return null;
	}
	
	public static void main(String[] args) {
		 
		
		try {
			ExcelTest1.getImage("");
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
